﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using motelmanagement;
using System.Diagnostics;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Metro;

namespace motelmanagement.useInterface
{
    public partial class MainForm : DevComponents.DotNetBar.Metro.MetroAppForm
    {
        //LoginControl _startup = null;
        LoginControls _logcon = null;
        StartupControls _startup = null;
        MetroBillCommands _Commands = null;
        public MainForm()
        {
            InitializeComponent();
            // Prepare commands
            _Commands = new MetroBillCommands();

            _Commands.ToggleStartControl = new Command(components);
            _Commands.ToggleStartControl.Executed += new EventHandler(ToggleStartControlExecuted);

            // Initialize Client related commands
            _Commands.ClientCommands.New = new Command(components); // We pass in components from Form so the command gets disposed automatically when form is disposed
            _Commands.ClientCommands.New.Executed += NewClientExecuted;
            _Commands.ClientCommands.Cancel = new Command(components);
            _Commands.ClientCommands.Cancel.Executed += CancelClientExecuted;
            _Commands.ClientCommands.Save = new Command(components);
            _Commands.ClientCommands.Save.Executed += SaveClientExecuted;
            // Invoice related commands
            _Commands.InvoiceCommands.New = new Command(components); // We pass in components from Form so the command gets disposed automatically when form is disposed
            //_Commands.InvoiceCommands.New.Executed += NewInvoiceExecuted;
            _Commands.InvoiceCommands.Cancel = new Command(components);
            //_Commands.InvoiceCommands.Cancel.Executed += CancelInvoiceExecuted;
            _Commands.InvoiceCommands.Save = new Command(components);
            //_Commands.InvoiceCommands.Save.Executed += SaveInvoiceExecuted;
            // General commands
            //_Commands.ChangeMetroTheme = new Command(components, new EventHandler(ChangeMetroThemeExecuted));
            //_Commands.NotImplemented = new Command(components, new EventHandler(NotImplementedExecuted));
            //_Commands.DevComponents = new Command(components, new EventHandler(DevComponentsExecuted));
            //_Commands.GettingStartedCommand = new Command(components, new EventHandler(GettingStartedExecuted));
            //Hien thi Login Control
            this.SuspendLayout();
            _logcon = new LoginControls();
            _logcon.Commands = _Commands;
            this.Controls.Add(_logcon);
            _logcon.BringToFront();
            _logcon.SlideSide = DevComponents.DotNetBar.Controls.eSlideSide.Left;
            _logcon.Click += new EventHandler(StartControl_Click);
            this.ResumeLayout(false);
            //Hien Thi Start up Control.
            this.SuspendLayout();
            _startup = new StartupControls();
            _startup.Commands = _Commands;
            this.Controls.Add(_startup);
            _startup.BringToFront();
            _startup.SlideSide = DevComponents.DotNetBar.Controls.eSlideSide.Right;
            _startup.Click += new EventHandler(StartControl_Click);
            this.ResumeLayout(false);
        }


        private void ToggleStartControlExecuted(object sender, EventArgs e)
        {
            _logcon.IsOpen = !_logcon.IsOpen;
            _startup.IsOpen = !_startup.IsOpen;
        }
        public EventHandler NewClientExecuted { get; set; }
        public EventHandler CancelClientExecuted { get; set; }
        public EventHandler SaveClientExecuted { get; set; }
        #region UI Code
        void StartControl_Click(object sender, EventArgs e)
        {
            if (_logcon.IsOpen)
            {
                _startup.IsOpen = true;
            }
            else
            {
                _startup.IsOpen = false;
            }
        }
        // set hien thanh bar top
        protected override void OnLoad(EventArgs e)
        {
            UpdateControlsSizeAndLocation1();
            UpdateControlsSizeAndLocation();
            base.OnLoad(e);
        }
        //Thu gon Login Control
        private Rectangle GetStartControlBounds()
        {
            int captionHeight = metroShell1.MetroTabStrip.GetCaptionHeight() + 2;
            Thickness borderThickness = this.GetBorderThickness();
            return new Rectangle((int)borderThickness.Left, captionHeight, this.Width - (int)borderThickness.Horizontal, this.Height - captionHeight - 1);
        }
        //Thu gon Start up control
        private Rectangle GetStartControlBounds1()
        {
            int captionHeight = metroShell1.MetroTabStrip.GetCaptionHeight() + 2;
            Thickness borderThickness = this.GetBorderThickness();
            return new Rectangle((int)borderThickness.Left, captionHeight, this.Width - (int)borderThickness.Horizontal, this.Height - captionHeight - 1);
        }
        private void UpdateControlsSizeAndLocation()
        {
            if (_logcon != null)
            {
                if (!_logcon.IsOpen)
                    _logcon.OpenBounds = GetStartControlBounds();
                else
                    _logcon.Bounds = GetStartControlBounds();
                if 
                    (!IsModalPanelDisplayed)
                    _logcon.BringToFront();
            }
            //metroToolbar1.Location = new Point((this.Width - metroToolbar1.Width) / 2, metroToolbar1.Parent.Height - metroToolbar1.Height - 1);
            //metroToolbar2.Location = new Point((this.Width - metroToolbar2.Width) / 2, metroToolbar2.Parent.Height - metroToolbar2.Height - 1);
        }
        private void UpdateControlsSizeAndLocation1()
        {
            if (_startup != null)
            {
                if (!_startup.IsOpen)
                    _startup.OpenBounds = GetStartControlBounds1();
                else
                    _startup.Bounds = GetStartControlBounds1();
                if (!IsModalPanelDisplayed)
                    _startup.BringToFront();
            }
            //metroToolbar1.Location = new Point((this.Width - metroToolbar1.Width) / 2, metroToolbar1.Parent.Height - metroToolbar1.Height - 1);
            //metroToolbar2.Location = new Point((this.Width - metroToolbar2.Width) / 2, metroToolbar2.Parent.Height - metroToolbar2.Height - 1);
        }
        protected override void OnResize(EventArgs e)
        {
            UpdateControlsSizeAndLocation1();
            UpdateControlsSizeAndLocation();
            base.OnResize(e);
        }
        #endregion

        private void metroShell1_Click(object sender, EventArgs e)
        {
           
        }


    }
}